package com.example.personal.mvvm.viewmodel

import androidx.lifecycle.MutableLiveData
import com.example.personal.api.PersonalApiManager
import com.example.personal.mvvm.bean.AttentionBean
import com.gsafety.library.Base.BaseViewModel
import com.gsafety.libraryktx.bean.LoadState
import com.gsafety.libraryktx.expand.enqueue
import com.gsafety.libraryktx.net.api.request.RequestParamsManager

class AttentionViewModel:BaseViewModel() {
    var loadValue = MutableLiveData<AttentionBean>()
    var loadState = MutableLiveData<LoadState>()
    var setAttendValue = MutableLiveData<Boolean>()
    var cancelAttendValue = MutableLiveData<Boolean>()
    fun requestWarnList(size:Int, current:Int,key:String){
        enqueue(PersonalApiManager.apiService.myWarnList(RequestParamsManager.myWarnList(size,current,key)),onSuccess={ result ->
            loadValue.value = result
            loadState.value = LoadState.Success()
        },onFail={ error->
            loadState.value = LoadState.Fail(error?: "")
        })
    }

    fun setAttention(pid:Int){
        enqueue(PersonalApiManager.apiService.setAttention(RequestParamsManager.setAttention(pid)),onSuccess={ result ->
            setAttendValue.value = result
        },onFail={ error->

        })
    }

    fun cancelAttention(pid:Int){
        enqueue(PersonalApiManager.apiService.cancelAttention(RequestParamsManager.setAttention(pid)),onSuccess={ result ->
            cancelAttendValue.value = result
        },onFail={ error->

        })
    }
}